﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class StringExtension
{
    /// <summary>
    /// 将string 转成 Vector3   "1,2,3"
    /// </summary>
    public static Vector3 ToVector3(this string str)
    {
        string[] erf_pos = str.Split(',');
        return new Vector3(float.Parse(erf_pos[0]), float.Parse(erf_pos[1]), float.Parse(erf_pos[2]));
    }
    
    /// <summary>
    /// 将string 转成 Vector3   "255,255,255"
    /// </summary>
    public static Color ToColor(this string str)
    {
        string[] erf_col = str.Split(',');
        return new Color(int.Parse(erf_col[0]), int.Parse(erf_col[1]), int.Parse(erf_col[2]));
    }
    
    /// <summary>
    /// 字符串切割
    /// 正常的切割字符串只能是单个字符
    /// </summary>
    public static string[] Split(this string originStr, string moreChar)
    {
        if (moreChar.Length <= 0) return null;
        else if(moreChar.Length == 1)
            return originStr.Split(moreChar[0]);
        else
            return System.Text.RegularExpressions.Regex.Split(originStr, moreChar);
    }

    public static bool IsNullOrEmpty(this string str)
    {
        return string.IsNullOrEmpty(str);
    }

    public static bool IsNotNullOrEmpty(this string str)
    {
        return !string.IsNullOrEmpty(str);
    }

    public static int ToInt(this string str)
    {
        return int.Parse(str);
    }

    public static float ToFloat(this string str)
    {
        return float.Parse(str);
    }
}
